<template>
  <el-dialog
    v-model="model['isShow']"
    :close-on-click-modal="false"
    destroy-on-close
    :title="model['isEdit'] ? '修改地图' : '新增地图'"
    width="50%"
  >
    <el-form
      ref="ruleFormRef"
      :model="imageData"
      :rules="rules"
      label-width="auto"
      class="demo-ruleForm"
      status-icon
      scroll-to-error
    >
      <el-form-item label="地图编号" prop="name">
        <el-input v-model="imageData.name" maxlength="8" placeholder="请输入" />
      </el-form-item>
      <el-form-item label="地图名称" prop="name">
        <el-input
          v-model="imageData.name"
          maxlength="10"
          placeholder="请输入"
        />
      </el-form-item>
      <el-form-item label="地图文件" prop="name">
        <el-upload
          v-model:file-list="fileList"
          class="upload-demo"
          action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
          :on-change="handleChange"
        >
          <el-button type="primary">点击上传</el-button>
          <template #tip>
            <div class="el-upload__tip">
              jpg/png files with a size less than 500kb
            </div>
          </template>
        </el-upload>
      </el-form-item>
      <el-form-item label="地图坐标" prop="name">
        <div class="flex flex-col">
          <el-form-item label="经度" prop="name">
            <el-input v-model="imageData.name" placeholder="请输入坐标经度" />
          </el-form-item>
          <el-form-item label="纬度" prop="name" class="mt-3">
            <el-input v-model="imageData.name" placeholder="请输入坐标纬度" />
          </el-form-item>
        </div>
      </el-form-item>

      <el-form-item label="指北信息" prop="name">
        <el-input v-model="imageData.name" placeholder="请输入指北角度" />
      </el-form-item>
      <el-form-item label="初始角度" prop="name">
        <el-input v-model="imageData.name" placeholder="请输入初始角度" />
      </el-form-item>
    </el-form>

    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary">保存</el-button>
        <el-button>取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { ref, reactive } from "vue";
import type { UploadProps, UploadUserFile } from "element-plus";

const model = defineModel({ default: { isShow: false, isEdit: false } });
const rules = reactive<any>([]);
const imageData = reactive<any>({});

const fileList = ref<UploadUserFile[]>([
  {
    name: "food.jpeg",
    url: "c169db754a9cdb76de548385c4f7677b.jpeg"
  }
  // {
  //   name: "food2.jpeg",
  //   url: "https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100"
  // }
]);

const uploadImage = () => {};
const handleChange: UploadProps["onChange"] = (uploadFile, uploadFiles) => {
  console.log(
    "%c [ uploadFile, uploadFiles ]-88",
    "font-size:13px; background:pink; color:#bf2c9f;",
    uploadFile,
    uploadFiles,
    fileList.value
  );
  // fileList.value = fileList.value.slice(-3);
};
</script>

<style lang="scss" scoped></style>
